package MediaOnline.General;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import MediaOnline.General.paramConst;
public class utilities {
	
	
	public static void updateMediaApk(Activity activity, String s)
    {
        try
        {
            HttpURLConnection httpurlconnection = (HttpURLConnection)(new URL(s)).openConnection();
            httpurlconnection.setRequestMethod("GET");
            httpurlconnection.setDoOutput(true);
            httpurlconnection.connect();
            File file = new File((new StringBuilder()).append(Environment.getExternalStorageDirectory()).append("/download/").toString());
            file.mkdirs();
            FileOutputStream fileoutputstream = new FileOutputStream(new File(file, paramConst.APK_TEMPLATEUPDATE));
            InputStream inputstream = httpurlconnection.getInputStream();
            byte abyte0[] = new byte[1024];
            do
            {
                int i = inputstream.read(abyte0);
                if(i == -1)
                {
                    fileoutputstream.close();
                    inputstream.close();
                    Intent intent = new Intent("android.intent.action.VIEW");
                    intent.setDataAndType(Uri.fromFile(new File((new StringBuilder()).append(Environment.getExternalStorageDirectory()).append("/download/").append(paramConst.APK_TEMPLATEUPDATE).toString())), "application/vnd.android.package-archive");
                    activity.startActivity(intent);
                    break;
                }
                fileoutputstream.write(abyte0, 0, i);
            } while(true);
        }
        catch(IOException ioexception)
        {
            ioexception.printStackTrace();
        }
    }
	
}
